<%@page pageEncoding="utf-8" contentType="text/html; charset=utf-8" %>
<%@ include file="/admin/include/init_admin.jsp" %>
<%@ page import="com.joinhawaii.admin.product.*" %>
<%
	HashList code001	= CommonUtil.getCodeList("001");	//섬코드
	HashList code005	= CommonUtil.getCodeList("005");	//종류
	HashList code007	= CommonUtil.getCodeList("007");	//종류
	HashList code011	= CommonUtil.getCodeList("011");	//숙박일수
	HashList code012	= CommonUtil.getCodeList("012");	//보험
	HashList code114	= CommonUtil.getCodeList("114");	//종류
	HashList code121	= CommonUtil.getCodeList("121");	//구분
	HashList codeHotel	= CommonUtil.getCodeList("hotel", "");	//호텔
	HashList codeEnjoy	= CommonUtil.getCodeList("enjoy", "");	//선택관광
	HashList codeCar	= CommonUtil.getCodeList("car", "");	//렌터카
	HashList codeUseYn	= CommonUtil.getCodeList("use_yn");

	String tabs_code	= StringUtil.nvl(request.getParameter("tabs_code"), "1");
	String job_type		= StringUtil.nvl(request.getParameter("job_type"),"U");
	String package_id	= StringUtil.nvl(request.getParameter("package_id"));


	HashMap infos = new HashMap();
	infos.put("package_id",	package_id);

	ProductDAO dao 			= new ProductDAO();
	HashList list 			= dao.selectPackageList(infos);
	HashList scheduleList	= dao.selectPackageSchedule(infos);
	HashList hotelList		= dao.selectPackageHotel(infos);
	HashList enjoyList		= dao.selectPackageEnjoy(infos);
	HashList carList		= dao.selectPackageCar(infos);

%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
	<title>조인하와이</title>
	<%@ include file="/admin/include/cssnjs.jsp"  %>
	<script type="text/javascript" src="/js/ajaxfileupload.js"></script>
	<script type="text/javascript" src="/SE2.3.1.O9858/js/HuskyEZCreator.js" charset="utf-8"></script>

	<script type="text/javascript">
	var oEditors = [];

	$(document).ready(function() {

		cfInitSE("package_include");
		//cfInitSE("package_exclude");
		cfInitSE("package_info");
		//cfInitSE("package_prepare");
		cfInitSE("package_notice");
		cfInitSE("package_schedule");


		//탭 초기화
		$('#tabs li[code="<%=tabs_code%>"]').removeClass('off').addClass('on');
		$('#tabs-<%=tabs_code%>').removeClass('hidden');

		/* 탭 클릭 */
		$('li', '#tabs').click(function(){
		    $('.on', '#tabs').removeClass('on').addClass('off');
		    $(this).addClass('on');

			$('#tabs-1:not(.hidden),#tabs-2:not(.hidden),#tabs-3:not(.hidden),#tabs-4:not(.hidden),#tabs-5:not(.hidden),#tabs-6:not(.hidden)').addClass('hidden');
			$('#tabs-'+$(this).attr('code')).removeClass('hidden');

			//참고사진 클릭시 SE 초기화
			if ($(this).attr('code') == '3') {
				cfInitSE("package_pic");
			}
		});






	<%	if (hotelList.size() == 0) {	%>
			fnAddRow('hotel');
	<%	}	%>

	<%	if (enjoyList.size() == 0) {	%>
			fnAddRow('enjoy');
	<%	}	%>

	<%	if (carList.size() == 0) {	%>
			fnAddRow('car');
	<%	}	%>


		$('select:[name="hotel.hotel_id"]').live('change', function() {
			var oRoom = $(this).closest('tr').find('select[name="hotel.room_id"]');
			//alert($(this).val())
			$.ajax({
				url: '/common/selectCode.do',
				type: "POST",
			    dataType: 'json',//html,text,json
			    data: { //파라미터
			    	code_gubn : 'room',
			    	hotel_id : $(this).val()
			    },
			    error: function(data, status, err){
			    	alert(err);
			    },
				success: function(data){
					oRoom.find('option').remove();
					for (var i = 0; i < data.list.length; i++) {
						oRoom.append('<option value="' + data.list[i].code + '">'+data.list[i].code_name+'</option>');
					}
			    }
			});
		});



		$('select:[name="enjoy.enjoy_id"]').live('change', function() {
			var oPrice = $(this).closest('tr').find('select[name="enjoy.price_id"]');
			//alert($(this).val())
			$.ajax({
				url: '/common/selectCode.do',
				type: "POST",
			    dataType: 'json',//html,text,json
			    data: { //파라미터
			    	code_gubn : 'price',
			    	enjoy_id : $(this).val()
			    },
			    error: function(data, status, err){
			    	alert(err);
			    },
				success: function(data){
					oPrice.find('option').remove();
					for (var i = 0; i < data.list.length; i++) {
						oPrice.append('<option value="' + data.list[i].code + '">'+data.list[i].code_name+'</option>');
					}
			    }
			});
		});
	});


	//기본정보 등록,수정
	function fnSave()
	{
		if (confirm(MSG_<%=job_type%>)) {
			oEditors.getById["package_include"].exec("UPDATE_CONTENTS_FIELD", []);
			//oEditors.getById["package_exclude"].exec("UPDATE_CONTENTS_FIELD", []);
			oEditors.getById["package_info"].exec("UPDATE_CONTENTS_FIELD", []);
			//oEditors.getById["package_prepare"].exec("UPDATE_CONTENTS_FIELD", []);
			oEditors.getById["package_notice"].exec("UPDATE_CONTENTS_FIELD", []);
			oEditors.getById["package_schedule"].exec("UPDATE_CONTENTS_FIELD", []);

			$('#saveForm').attr('action', './packageSave.do');
			$('#saveForm').submit();
		}
	}
	
	//기본정보 삭제
	function fnDelete()
	{
		if (confirm(MSG_D)) {
			document.saveForm.job_type.value = "D";
			$('#saveForm').attr('action', './packageSave.do');
			$('#saveForm').submit();
		}
	}

	function fnPicSave() {
		oEditors.getById["package_pic"].exec("UPDATE_CONTENTS_FIELD", []);
		$('#picSaveForm').submit();
	}

	//상세일정 등록,수정
	function fnScheduleSave()
	{
		if (confirm(MSG_<%=job_type%>)) {
			oEditors.getById["package_schedule"].exec("UPDATE_CONTENTS_FIELD", []);
			$('#scheduleForm').attr('action', './packageScheduleSave.do?tabs_code=2');
			$('#scheduleForm').submit();
		}
	}


	//상품구성 행추가
	function fnAddRow(gubn) {

		if (gubn == "hotel") {
			var txt = '<tr><td>'
					+ '<select name="hotel.hotel_id" class="w260"><%= StringUtil.makeOptionByGroup(codeHotel, "") %></select> '
					+ '<select name="hotel.room_id" class="w300"></select> '
					+ '<select name="hotel.stay_day" class="w60"><%= StringUtil.makeOption(code011, "") %></select> '
					+ '<img src="/images/admin/btn_remove.gif" class="pointer" onclick="fnDeleteRow(this)"/></td></tr>';
			$("#hotel").append(txt);
		}
		else if (gubn == "enjoy") {
			var txt = '<tr><td>'
				+ '<select name="enjoy.enjoy_id" class="w260"><%= StringUtil.makeOptionByGroup(codeEnjoy, "") %></select> '
				+ '<select name="enjoy.price_id" class="w300"></select> '
				+ '<img src="/images/admin/btn_remove.gif" class="pointer" onclick="fnDeleteRow(this)"/></td></tr>';
			$("#enjoy").append(txt);
		}
		else if (gubn == "car") {
			var txt = '<tr><td>'
					+ '<select name="car.car_id" class="w260"><%= StringUtil.makeOption(codeCar, "") %></select> '
					+ '<img src="/images/admin/btn_remove.gif" class="pointer" onclick="fnDeleteRow(this)"/>'
					+ '</td></tr>';
			$("#car").append(txt);
		}
	}


	//행삭제
	function fnDeleteRow(oThis) {
		$(oThis).closest('tr').remove();
	}

	</script>
</head>
<body>
<div id="wrap">
	<div id="top">
		<%@ include file="/admin/include/top.jsp" %>
	</div>
	<div id="page">
		<div id="menu">
			<%@ include file="/admin/include/leftMenu.jsp" %>
		</div>
		<div id="contents">
			<div class="menu_title">
				<h1>할인패키지</h1>
				<p>관리자 > 상품관리 > <b>할인패키지</b></p>
			</div>
			<div class="clear line_01"></div>


			<ul id="tabs" class="tab_01 mt15">
			    <li class="off" code="1"><p>1. 기본사항</p></li>
			<%	if ("U".equals(job_type)) { %>
			    <li class="off" code="2"><p>2. 여행일정</p></li>
			    <li class="off" code="3"><p>3. 참고사진</p></li>
			    <li class="off" code="4"><p>4. 상품구성</p></li>
			<%	} %>
			</ul>


			<div id="tabs-1" class="hidden mt15">

			<form id="saveForm" method="post" action="" enctype="multipart/form-data">
			<input type="hidden" name="job_type" value="<%= job_type %>"/>
			<input type="hidden" name="package_id" value="<%= list.get("package_id", 0) %>"/>


			<table cellpadding="0" cellspacing="0" class="table_01 mt5">
			<colgroup>
				<col width="100px"/>
				<col width="280px"/>
				<col width="100px"/>
				<col/>
			</colgroup>
			<tbody>
				<tr>
					<th><p>패키지명</p></th>
					<td colspan="3" class="brx">
						<input type="text" name="package_name" value="<%= list.get("package_name", 0) %>"  maxlength="255" class="wmax"/>
					</td>
				</tr>
				<tr>
					<th><p>코드</p></th>
					<td><input type="text" name="package_code" value="<%= list.get("package_code", 0) %>" maxlength="100" class="w260" /></td>
					<th><p>종류</p></th>
					<td class="brx">
	        			<select name="package_type" style="width:130">
	        			<%= StringUtil.makeOption(code007, list.get("package_type", 0)) %>
						</select>
					</td>
				</tr>
				<tr>
					<th><p>추천여부</p></th>
					<td>
						<input type="checkbox" name="recommend_yn" value="Y" <%= StringUtil.checked("Y", list.get("recommend_yn", 0)) %>" /> 추천
						<input type="checkbox" name="main_yn" value="Y" <%= StringUtil.checked("Y", list.get("main_yn", 0)) %>" /> 특가상품
					</td>
					<th><p>구분</p></th>
					<td class="brx">
	        			<select name="package_gubn" style="width:130">
	        			<%= StringUtil.makeOption(code121, list.get("package_gubn", 0)) %>
						</select>
					</td>
				</tr>
				<tr>
					<th><p>여행일정</p></th>
					<td><input type="text" name="travel_schedule" value="<%= list.get("travel_schedule", 0) %>" maxlength="100" class="w260" /></td>
					<th><p>가격</p></th>
					<td class="brx"><input type="text" name="sales_price" value="<%= list.get("sales_price", 0) %>" maxlength="100" class="w260" /></td>
				</tr>
				<tr>
					<th><p>문의 및 예약</p></th>
					<td><input type="text" name="help_desk" value="<%= list.get("help_desk", 0) %>" class="w260"   maxlength="500" /></td>
					<th><p>사용여부</p></th>
					<td class="brx">
						<select name="use_yn" class="w120">
						<%= StringUtil.makeOption(codeUseYn, list.get("use_yn", 0)) %>
						</select>
					</td>
				</tr>
				<tr>
					<th><p>지역</p></th>
					<td colspan="3"  class="brx"><input type="text" name="location" value="<%= list.get("location", 0) %>" class="wmax"   maxlength="500" /></td>
				</tr>
				<tr>
					<th><p>대표사진</p></th>
					<td colspan="3" class="brx">
					<%	if ("C".equals(job_type)) { %>
								등록후 업로드
					<%	} else { %>
						<input type="file" name="img_path_00" value="" class="w300" />
		        		<a href="<%= list.get("img_path_00",0) %>" target="_blank"><%= list.get("img_path_00",0) %></a>
		        	<%	} %>
					</td>
				</tr>
				<tr>
					<th><p>상품안내</p></th>
					<td colspan="3" class="brx">
						<textarea name="package_include" id="package_include" style="width:860px; height:200px"><%= list.get("package_include", 0) %></textarea>
					</td>
				</tr>
				<tr>
					<th><p>상품정보</p></th>
					<td colspan="3" class="brx">
						<textarea name="package_info" id="package_info" style="width:860px; height:200px"><%= list.get("package_info", 0) %></textarea>
					</td>
				</tr>
				<tr>
					<th><p>알림</p></th>
					<td colspan="3" class="brx">
						<textarea name="package_notice" id="package_notice" style="width:860px; height:200px"><%= list.get("package_notice", 0) %></textarea>
					</td>
				</tr>
			<!--
				<tr>
					<th><p>불포함사항<br>(삭제예정)</p></th>
					<td colspan="3" class="brx">
						<textarea name="package_exclude" id="package_exclude" style="width:860px; height:200px"><%= list.get("package_exclude", 0) %></textarea>
					</td>
				</tr>
				<tr>
					<th><p>준비물<br>(삭제예정)</p></th>
					<td colspan="3" class="brx">
						<textarea name="package_prepare" id="package_prepare" style="width:860px; height:200px"><%= list.get("package_prepare", 0) %></textarea>
					</td>
				</tr>
			-->
			</tbody>
			</table>


			<div class="mt20 mb10 c">
				<a href="./packageList.jsp"><img src="/images/admin/btn_list.gif"/></a>
			<%	if ("U".equals(job_type)) { %>
					<a href="#nohref" onclick="fnSave()"><img src="/images/admin/btn_update.gif" /></a>
					<a href="#nohref" onclick="fnDelete()"><img src="/images/admin/btn_delete.gif" /></a>
			<%	} else if ("C".equals(job_type)) { %>
					<a href="#nohref" onclick="fnSave()"><img src="/images/admin/btn_register.gif" /></a>
			<%	} %>
			</div>

			</form>

			</div>


			<!-- 여행일정 -->
			<div id="tabs-2" class="hidden mt15">

			<form id="scheduleForm" method="post" action="">
			<input type="hidden" name="job_type" value="<%= job_type %>"/>
			<input type="hidden" name="package_id" value="<%= package_id %>"/>


			<table cellpadding="0" cellspacing="0" class="table_01 mt5" >
			<colgroup>
				<col width="100px"/>
				<col/>
			</colgroup>
			<tbody>
				<tr>
					<th width="100px"><p></p></th>
					<td class="brx">
						<textarea name="package_schedule" id="package_schedule" style="width:860px; height:600px" ><%= list.get("package_schedule", 0) %></textarea>
					</td>
				</tr>
			</tbody>
			</table>

			<div class="mt20 mb10 c">
				<a href="./packageList.jsp"><img src="/images/admin/btn_list.gif"/></a>
				<a href="#nohref" onclick="fnScheduleSave()"><img src="/images/admin/btn_update.gif" /></a>
			</div>

			</form>

			</div>


			<!-- 참고사진 -->
			<div id="tabs-3" class="hidden mt15">
				<form id="picSaveForm" method="post" action="./picSave.do?tabs_code=3" enctype="multipart/form-data">
				<input type="hidden" name="pic_name" id="pic_name" value="package"/>
				<input type="hidden" name="pic_id" value="<%= list.get("package_id", 0) %>"/>
				<div class="ml10 mr10">
					<textarea name="package_pic" id="package_pic" style="width:100%; height:800px" ><%= list.get("package_pic", 0) %></textarea>
				</div>
				<div class="mt20 mb10 c">
					<a href="./packageList.jsp"><img src="/images/admin/btn_list.gif"/></a>
					<a href="#nohref" onclick="fnPicSave()"><img src="/images/admin/btn_update.gif" /></a>
				</div>
				</form>
			</div>


			<!-- 상품구성 -->
			<div id="tabs-4" class="hidden mt15">

			<form id="productForm" method="post" action="./packageProductSave.do?tabs_code=4">
			<input type="hidden" name="job_type" value="<%= job_type %>"/>
			<input type="hidden" name="package_id" value="<%= list.get("package_id", 0) %>"/>


			<table cellpadding="0" cellspacing="0" class="table_01 mt5">
			<colgroup>
				<col width="100px"/>
				<col/>
			</colgroup>
			<tbody>
				<tr>
					<th><p>국제선</p></th>
					<td class="brx">
						<select name="block_yn" class="w100">
							<%= StringUtil.makeOption(code114, list.get("block_yn", 0)) %>
						</select>
						<select name="air_code" class="w120">
						<%= StringUtil.makeOption(code005, list.get("air_code", 0)) %>
						</select>
					</td>
				</tr>
				<tr>
					<th><p>주내선</p></th>
					<td class="brx">
						<input type="text" name="fly_count" value="<%= list.get("fly_count", 0) %>" class="w100 r"/> 회
					</td>
				</tr>
				<tr>
					<th><p>호텔 <img src="/images/admin/btn_add.gif" style="cursor:hand" onclick="fnAddRow('hotel')"/></p>
					</th>
					<td class="brx">

						<table cellpadding="0" cellspacing="0" class="table_no">
						<tbody id="hotel">
				<%
					for (int i = 0; i < hotelList.size(); i++) {
						HashMap param = new HashMap();
						param.put("code_gubn", "room");
						param.put("hotel_id", hotelList.get("hotel_id",i));
						HashList codeRoom = CommonUtil.getCodeList(param);
				%>
						<tr>
							<td>
							<select name="hotel.hotel_id" class="w260">
							<%= StringUtil.makeOptionByGroup(codeHotel, hotelList.get("hotel_id", i)) %>
							</select>
							<select name="hotel.room_id" class="w300">
							<%= StringUtil.makeOption(codeRoom, hotelList.get("room_id", i)) %>
							</select>
							<select name="hotel.stay_day" class="w60">
							<%= StringUtil.makeOption(code011, hotelList.get("stay_day", i)) %>
							</select>
							<img src="/images/admin/btn_remove.gif" class="pointer" onclick="fnDeleteRow(this)"/>
							</td>
						</tr>
				<%	} %>
						</tbody>
						</table>

					</td>
				</tr>
				<tr>
					<th><p>선택관광 <img src="/images/admin/btn_add.gif" class="pointer" onclick="fnAddRow('enjoy')"/></p></th>
					<td class="brx">

						<table cellpadding="0" cellspacing="0" class="table_no">
						<tbody id="enjoy">
				<%
					for (int i = 0; i < enjoyList.size(); i++) {
						HashMap param = new HashMap();
						param.put("code_gubn", "price");
						param.put("enjoy_id", enjoyList.get("enjoy_id",i));
						HashList codePrice = CommonUtil.getCodeList(param);
				%>
						<tr>
							<td>
							<select name="enjoy.enjoy_id" class="w260">
							<%= StringUtil.makeOptionByGroup(codeEnjoy, enjoyList.get("enjoy_id", i)) %>
							</select>
							<select name="enjoy.price_id" class="w300">
							<%= StringUtil.makeOption(codePrice, enjoyList.get("price_id", i)) %>
							</select>
							<img src="/images/admin/btn_remove.gif" class="pointer" onclick="fnDeleteRow(this)"/>
							</td>
						</tr>
				<%	} %>
						</tbody>
						</table>
					</td>
				</tr>
				<tr>
					<th><p>렌터카 <img src="/images/admin/btn_add.gif" class="pointer" onclick="fnAddRow('car')"/></p></th>
					<td class="brx">
						<table cellpadding="0" cellspacing="0" class="table_no">
						<tbody id="car">
				<%
					for (int i = 0; i < carList.size(); i++) {
				%>
						<tr>
							<td>
							<select name="car.car_id" class="w260">
							<%= StringUtil.makeOption(codeCar, carList.get("car_id", i)) %>
							</select>
							<img src="/images/admin/btn_remove.gif" class="pointer" onclick="fnDeleteRow(this)"/>
							</td>
						</tr>
				<%	} %>
						</tbody>
						</table>
					</td>
				</tr>
				<tr>
					<th><p>보험</p></th>
					<td class="brx">
						<select name="insure_id" class="w100">
						<%= StringUtil.makeOption(code012, list.get("insure_id", 0)) %>
						</select>
					</td>
				</tr>
				<tr>
					<th><p>기타</p></th>
					<td class="brx">
						<input type="text" name="etc_amt" value="<%= list.get("etc_amt", 0) %>" class="w100 r"/> $
					</td>
				</tr>
			</tbody>
			</table>


			<div class="mt20 mb10 c">
				<a href="./packageList.jsp"><img src="/images/admin/btn_list.gif"/></a>
				<input type="image" class="button" src="/images/admin/btn_update.gif"/>
			</div>

			</form>

			</div>

		</div>
	</div>
</div>

</body>
</html>
